﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;
using System.IO;

public partial class controls_admin_NeedAdd : Pages_Base
{
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadSetting();
            base.loadCategories(ddlCategories, 4);
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable admin = (DataTable)Session["Admin"];
            string title = txtTitle.Text.Trim();
            int category_id = Convert.ToInt32(ddlCategories.SelectedValue);
            string result = BO_Needs.Insert(category_id, title, 1, DateTime.Now, admin.Rows[0]["USER_NAME"].ToString(), DateTime.Now, "", true);
            if (result.Equals("0"))
                divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Chưa thực hiện được .");
            else
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thực hiện thành công .");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
    private void loadSetting()
    {
        objDT = BO_Settings.SelectByGroupId(12, 1);
        foreach (DataRow dr in objDT.Rows)
        {
            string value = dr["SETTING_VALUE"].ToString();
            switch (dr["SETTING_KEY"].ToString())
            {
                case "NOTE_TITLE":
                    NOTE_TITLE.InnerText = value;
                    break;
                case "NOTE_CATEGORY":
                    NOTE_CATEGORY.InnerText = value;
                    break;
            }
        }
    }
}
